package com.ipartek.formacion.miprimerwebapp.sevlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MyPrimerSevletP5
 */
public class MyPrimerSevletP5 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public MyPrimerSevletP5() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("entramos por GET");
		PrintWriter out;
		String title = "Simple Servlet Output";
		// primero selecciona el tipo de contenidos y otros campos de
		// cabecera de la respuesta
		response.setContentType("text/html");
		// Luego escribe los datos de la respuesta
		out = response.getWriter();
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<H1>" + title + "</H1>");
		out.println("<P>This is output from SimpleServlet.");
		out.println("</BODY></HTML>");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ServletOutputStream out;
		out = response.getOutputStream();
		System.out.println("Entramos por POST");
		String uno = request.getParameter("user");
		out.print(uno);
		out.print(" ");
		String dos = request.getParameter("pass");
		out.print(dos);
	}

}
